package com.heima.zuoye.day11.timu2;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import javax.xml.parsers.SAXParser;
import java.util.List;

public class Demo1 {
    public static void main(String[] args) throws DocumentException {
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read("D:\\JAVA\\JavaSE\\JavaAdvance\\moudent01\\src\\com\\heima\\zuoye\\day11\\timu2\\book.xml");
        Element root = read.getRootElement();
        List<Element> elements = root.elements();
        for (Element element : elements) {
            Attribute id = element.attribute("id");
            String idValue = id.getValue();
            Element name = element.element("name");
            String nameText = name.getText();
            Element pesd = element.element("pesd");
            String pesdText = pesd.getText();
            Element tim = element.element("tim");
            String timText = tim.getText();
            Element price = element.element("price");
            String priceText = price.getText();
            System.out.println(idValue + nameText + pesdText + timText + priceText);
        }
        /*for (Element element : elements) {
            Attribute id = element.attribute("id");
            String idValue = id.getValue();
            Attribute name = element.attribute("name");
            String nameValue = name.getValue();
            Attribute pesd = element.attribute("pesd");
            String pesdValue = pesd.getValue();
            Attribute tim = element.attribute("tim");
            String timValue = pesd.getValue();
            Attribute price = element.attribute("price");
            String priceValue = pesd.getValue();

            System.out.println(pesdValue + timValue + priceValue);
        }*/
    }
}
